#include <stdlib.h>
#include <time.h>

inline void swap(int* arr, int idx1, int idx2)
/* Swap two elements of an array by their indices */
{
    /*
    arr[idx1] = arr[idx1] ^ arr[idx2];
    arr[idx2] = arr[idx1] ^ arr[idx2];
    arr[idx1] = arr[idx1] ^ arr[idx2];
    */
    int tmp = arr[idx1];
    arr[idx1] = arr[idx2];
    arr[idx2] = tmp;
}

void initRandomSeed()
/* Initialize the ramdon seed */
{
    srand(time(NULL));
}

void randomSelection(int* arr, int p, int r)
/* Selection a ramdon pivot and place it to p */
{
    swap(arr, p, p+rand()%(r-p+1));
}

int partition(int* arr, int p, int r)
/* Partition the elements between p and r of an array           */
/* Return an integer indicating the final position of the pivot */
{
    // select an random pivot and place it to the first position ..
    randomSelection(arr, p, r);
    
    // loop partition ..
    int i=p;
    for(int j=p+1;j<=r;++j) {
        if(arr[j]<=arr[p]) {
            ++i;
            swap(arr, i, j);
        }
    }
    
    // place the pivot to the correct position ..
    swap(arr, p, i);
    
    // return the index of pivot ..
    return i;
}

void Quicksort_internalCalling(int* arr, int p, int r)
/* Quicksort the elements from p to r of an array */
/* Internal calling                               */
{
    if(p<r) {
        int q = partition(arr, p, r);
        Quicksort_internalCalling(arr, p, q-1);
        Quicksort_internalCalling(arr, q+1, r);
    }
}

void Quicksort(int* arr, int p, int r)
/* Quicksort the elements from p to r of an array */
/* Client calling                                 */
{
    // initialize the random seed ..
    initRandomSeed();
    
    // call the internal function of Quicksort ..
    Quicksort_internalCalling(arr, p, r);
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, ivl;
    int arr[100050];
    
    while(scanf("%d %d", &n, &ivl), !(n==0 && ivl==0)) {
        // read the numbers ..
        for(int i=0;i<n;++i) scanf("%d", arr+i);
        
        // sort ..
        Quicksort(arr, 0, n-1);
        
        // output the required result ..
        printf("%d",arr[0]);
        for(int i=ivl;i<n;i+=ivl) printf(" %d",arr[i]);
        if(n!=0) printf("\n");
    }
    
    return 0;
}


